package com.yeqian.service.impl;

import com.yeqian.pojo.Admin;
import com.yeqian.service.AdminService;
import com.yeqian.service.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;

/**
 * @Author : yeqian
 * @Date : 2020/12/30 18:43
 * <p>
 * 管理员服务实现类
 */
@Service
@Transactional
public class AdminServiceImpl extends BaseService implements AdminService {

    /**
     * 注册用户
     *
     * @param admin
     * @return void
     * @author yeqian
     * @date 2021/1/14 14:43
     */
    @Override
    public void registAdmin(Admin admin) {
        adminMapper.registAdmin(admin);
    }

    /**
     * 查询标签名
     *
     * @param
     * @return java.util.List<java.lang.String>
     * @author yeqian
     * @date 2021/1/10 14:59
     */
    @Override
    public List<String> getUrl() {
        List<String> urls = adminMapper.getUrl();
        List<String> urlList = new LinkedList<>();
        //截取成我们可以删除的url
        for (String url : urls) {
            String[] split = url.split("com/");
            urlList.add(split[1]);
        }
        return urlList;
    }

    /**
     * 查询作者名
     *
     * @param authorId
     * @return java.lang.String
     * @author yeqian
     * @date 2021/1/6 15:17
     */
    @Override
    public String getAuthorName(Integer authorId) {
        return adminMapper.getArticleName(authorId);
    }

    /**
     * 修改管理员基本信息
     *
     * @param admin
     * @return void
     * @author yeqian
     * @date 2021/1/3 17:14
     */
    @Override
    public void updateUser(Admin admin) {
        adminMapper.updateUser(admin);
    }

    /**
     * 根据用户名查询管理员
     *
     * @param username
     * @return com.yeqian.pojo.User
     * @author yeqian
     * @date 2020/12/30 23:06
     */
    @Override
    public Admin getUserByUserName(String username) {
        return adminMapper.getUserByUserName(username);
    }
}
